{extend name="admin/base" /} {block name="resources"/}
<style type="text/css">
.required{
	color:red;margin-right:10px;
}
</style>
{/block}{block name="main"}
<div class="set-style">
	<dl>
		<dt><span class="required">*</span>物流公司名称:</dt>
		<dd>
			<p>
				<input id="company_name" type="text" value="{$expressCompany.company_name}">
			</p>
			<p class="error">请输入物流公司名称</p>

		</dd>
	</dl>
	<dl>
		<dt>物流公司编号:</dt>
		<dd>
			<p>
				<input id="express_no" type="text" value="{$expressCompany.express_no}">
			</p>
		</dd>
	</dl>
	<dl>
		<dt>联系电话:</dt>
		<dd>
			<p>
				<input id="phone" type="text" value="{$expressCompany.phone}">
			</p>
			<p class="error">联系电话格式不正确</p>
		</dd>
	</dl>
	<dl>
		<dt>物流公司logo:</dt>
		<dd>
			<div class="class-logo">
				<p>
					<img id="imglogo" src="__ROOT__/{$expressCompany.express_logo}">
				</p>
			</div>
			<div class="ncsc-upload-btn">
				<a href="javascript:void(0);">
					<span>
						<input hidefocus="true" size="1" class="input-file" name="file_upload" id="uploadImg" type="file" onchange="imgUpload(this);">
						<input type="hidden" id="logo" value="{$expressCompany.express_logo}" />
					</span>
					<p><i class="fa fa-cloud-upload text"></i>上传图片</p>
				</a>
			</div>
			<p class="hint">
				<br><span style="color: orange;">建议使用宽100像素-高100像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span>
			</p>
		</dd>
	</dl>
	<dl>
		<dt>排序:</dt>
		<dd>
			<p>
				<input id="orders" type="number" value="{$expressCompany.orders}">
			</p>
			<p class="error">请输入排列序号</p>
		</dd>
	</dl>
	<dl>
		<dt>是否启用物流:</dt>
			<dd>
					<input id="is_enabled" type="checkbox" class="checkbox" {if condition="$expressCompany.is_enabled eq 1"}checked="checked"{/if} /> 
			</dd>
	</dl>
	
	<dl>
		<dt>是否设置为默认:</dt>
		<dd><input id="is_default" type="checkbox" class="checkbox" {if condition="$expressCompany.is_default eq 1"}checked="checked"{/if}/></dd>
	</dl>
	<input type="hidden" id="co_id" value="{$expressCompany.co_id}">
	<button class="edit_button" onclick="updataExpressCompanyAjax();">提交</button>

</div>
<script src="ADMIN_JS/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>

 <script>
	/**
	 *模块输入信息验证
	 */
	function verify(company_name, phone,orders) {
		if (company_name == '') {
			$("#company_name").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		}
		// if (express_no == '') {
		// 	$("#express_no").parent().next().show();
		// 	return false;
		// } else {
		// 	$(".error").hide();
		// }
// 		if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))) {
// 			$("#phone").parent().next().show();
// 			return false;
// 		} else {
// 			$(".error").hide();
// 		}
		return true;
	/* 	if (orders == '') {
			$("#orders").parent().next().show();
			return false;
		} else {
			$(".error").hide();
		} */
	}
	/**
	 *添加物流公司
	 **/
	function updataExpressCompanyAjax() {
		var company_name = $("#company_name").val();
		var express_no = $("#express_no").val();
		var company_logo = $("#logo").val();
		var phone = $("#phone").val();
		var orders = $("#orders").val();
		var co_id = $("#co_id").val();
		var is_default = 0;
		if($("#is_enabled").prop("checked")){
			var is_enabled = 1;
		}else{
			var is_enabled = 0;
		}
		if($("#is_default").prop("checked")){
			 is_default = 1;
		}
		if(!verify(company_name,phone,orders)){
			return false;
		}
		$.ajax({
			type : "post",
			url : "{:__URL('ADMIN_MAIN/express/updateexpresscompany')}",
			data : {
				'company_name' : company_name,
				'express_no' : express_no,
				'express_logo' : company_logo,
				'phone' : phone,
				'is_enabled' : is_enabled,
				'orders':orders,
				'co_id':co_id,
				'is_default':is_default
			},
			async : true,
			success : function(data) {
				if (data['code'] > 0) {
					$("#dialog").dialog({
						buttons : {
							"确定" : function() {
								$(this).dialog('close');
							}
						},
						contentText : data["message"],
						time : 1,
						timeHref : __URL("ADMIN_MAIN/express/expresscompany"),
					});

				} else {
					$("#dialog").dialog({
						buttons : {
							"确定,#e57373" : function() {
								$(this).dialog('close');
							}
						},
						contentText : data["message"]
					});
				}
			}
		});
		
	}
	/**
	 *图片上传
	 */
	function imgUpload(event) {
		var fileid = $(event).attr("id");
		var data = { 'file_path' : UPLOADEXPRESS };
		uploadFile(fileid,data,function(res){
			if(res.code){
				$("#imglogo").attr("src","__UPLOAD__/"+res.data);
				$("#logo").val(res.data);
				showTip(res.message,"success");
			}else{
				showTip(res.message,"error");
			}
		});
	}
</script>
{/block}
